package cn.itcast.blog.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import cn.itcast.blog.domain.AjaxResponse;
import cn.itcast.blog.domain.Category;
import cn.itcast.blog.service.CategoryService;
/**
 * 刷新的时候，点击重新加载框架
 * @author 16604
 *
 */
@WebServlet(urlPatterns="/category_find")
public class CategoryFindServlet extends HttpServlet{
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println(1);
		
		CategoryService categoryService = new CategoryService();
		
		List<Category> findByAll = categoryService.findByAll();
		
		AjaxResponse ajaxResponse = new AjaxResponse();
		ajaxResponse.setCode(0);
		ajaxResponse.setCount(100);
		ajaxResponse.setMsg("");
		ajaxResponse.setData(findByAll);
		
		String string = JSON.toJSONString(ajaxResponse);
		
		resp.setContentType("application/json;charset=utf-8");
		resp.getWriter().write(string);
		
	}
}
